package exercises.leetcode;

/**
 * <a href="">
 * </a>
 *
 * <p><span color="#87CEEB">描述:</span>
 *
 * @author or2
 * @date 2021年11月20日 时间: 20:40
 */
public class No151 {
    public String reverseWords(String s) {
        s = s.trim(); if (s.isBlank()) return "";
        String[] words = s.split("\\s+");
        for (int i = 0,length = words.length, len = length >> 1; i < len; i++) {
            String temp = words[i];
            words[i] = words[length - 1 - i];
            words[length - i - 1] = temp;
        }
        var res = new StringBuilder();
        for (String word : words) res.append(word.trim()).append(" ");

        return String.valueOf(res.deleteCharAt(res.length() - 1));
    }
}
